package h0723;

import java.util.*;

/**
  * @description 石头剪刀布游戏
  * @author 不知名帅哥
  * @date 2024/7/23 22:22
  * @version 1.0
*/
public class RockPaperScissors {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        Map<String,String> map=new HashMap<>();
        while (sc.hasNextLine()){
            String[] s = sc.nextLine().split(" ");
            map.put(s[0],s[1]);
        }
        sc.close();
        //map存放
        getResult(map);
    }

    private static void getResult(Map<String, String> map) {
        Set<Map.Entry<String, String>> entries = map.entrySet();
        List<String[]> alist=new LinkedList<>();
        List<String[]> blist=new LinkedList<>();
        List<String[]> clist=new LinkedList<>();
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (value.equals("A")) {
                alist.add(new String[]{key,value});
            }else if (value.equals("B")){
                blist.add(new String[]{key,value});
            }else {
                clist.add(new String[]{key,value});
            }
        }
        int aSize = alist.size();
        int bSize = blist.size();
        int cSize = clist.size();

        if (aSize!=0&&bSize!=0&&cSize!=0){ //三个手势都存在
            System.out.println("NULL");
        }else if (aSize!=0&&bSize!=0){
            alist.stream().map(strings -> strings[0]).sorted().forEach(System.out::println);
        }else if (aSize!=0&&cSize!=0){
            clist.stream().map(strings -> strings[0]).sorted().forEach(System.out::println);
        }else if (bSize!=0&&cSize!=0){
            blist.stream().map(strings -> strings[0]).sorted().forEach(System.out::println);
        }else {
            System.out.println("NULL");
        }
    }
}
